home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / flilib.zip / FLISRC.ZIP / FCCOMP.C < prev    next >
C/C++ Source or Header  |  1989-11-17  |  2KB  |  87 lines

  1. /* fii_fccomp.c -  code used to delta compress colors. */
  2.  
  3. #include "aai86.h"
  4. #include "aaflisav.h"
  5. #include "aafii.h"
  6.  
  7. /* fii_fccomp - compress an rgb triples color map just doing 'skip' compression */
  8. Cbuf *fii_fccomp(Cmap *s1, Cmap *s2, USHORT *cbuf, int count)
  9. {
  10. USHORT wcount, i;
  11. Cbuf *c;
  12. USHORT op_count;
  13. USHORT dif_count;
  14. USHORT same_count;
  15. USHORT next_match;
  16. USHORT bcount;
  17. Cmap *s2x;
  18. USHORT c3;
  19.  
  20. c = (Cbuf *)(cbuf+1);
  21. op_count = 0;
  22. count *= 3;
  23. wcount = i86_wcompare(s1, s2, count>>1);
  24. wcount <<= 1;
  25. if (wcount == count)
  26.     return(c);    /* stupid way to say got nothing... */
  27. for (;;)
  28.     {
  29.     /* first find out how many words to skip... */
  30.     c3 = (i86_bcompare(s1, s2, count)/3);
  31.     wcount = c3*3;
  32.     if ((count -= wcount) == 0)
  33.         goto OUT;    /* same until the end... */
  34.     *c++ = c3;
  35.     s1 += wcount;
  36.     s2 += wcount;
  37.     op_count++;
  38.  
  39.     /* figure out how long until the next worthwhile "skip" */
  40.     dif_count = 0;
  41.     bcount = count;
  42.     for (;;)
  43.         {
  44.         wcount = i86_bcontrast(s1,s2,bcount)/3;
  45.         dif_count += wcount;
  46.         wcount *= 3;
  47.         s1 += wcount;
  48.         s2 += wcount;
  49.         bcount -= wcount;
  50.         if (bcount >= 3)
  51.             {
  52.             if ((wcount = i86_bcompare(s1,s2,3)) == 3)
  53.                 {
  54.                 break;
  55.                 }
  56.             else
  57.                 {
  58.                 dif_count += 1;
  59.                 s1 += 3;
  60.                 s2 += 3;
  61.                 bcount -= 3;
  62.                 }
  63.             }
  64.         else
  65.             {
  66.             break;
  67.             }
  68.         }
  69.     *c++ = dif_count;
  70.     dif_count *= 3;
  71.     s2 -= dif_count;
  72.     count -= dif_count;
  73.     for (;;)
  74.         {
  75.         if (dif_count == 0)
  76.             break;
  77.         dif_count -= 1;
  78.         *c++ = *s2++;
  79.         }
  80.     if (count <= 0)
  81.         break;
  82.     }
  83. OUT:
  84. *cbuf = op_count;
  85. return(i86_enorm_ptr(c));
  86. }
  87.